/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;


/**
 * abstract base class for sensor data
 *
 * @author Merijn Zengers
 */
@Entity
@Table(name = "SENSOR_DATA")
public class SensorData implements Serializable {


    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator="SensorDataGen")
    @TableGenerator(name="SensorDataGen", table="SENSORDATA_GEN", pkColumnName="PK",valueColumnName="AID")
    @Column(name = "ID")
    private long id;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name = "DATA_FILE_ID")
    private SensorDataFile sensorDataFile;

    private double longtitude;

    private double latitude;

    protected SensorData(){
    }

    public SensorData (SensorDataFile sensorDataFile, double longtitude, double latitude){
        this.sensorDataFile = sensorDataFile;
        this.latitude = latitude;
        this.longtitude = longtitude;
    }

    public SensorDataFile getDataSensorFile() {
        return sensorDataFile;
    }

    public void setDataSensorFile(SensorDataFile geoDataSensorFile) {
        this.sensorDataFile = geoDataSensorFile;
    }

    public void setId(long id){
        this.id = id;
    }

    public long getId() {
        return id;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongtitude() {
        return longtitude;
    }

    public void setLongtitude(double longtitude) {
        this.longtitude = longtitude;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final SensorData other = (SensorData) obj;
        if (this.id != other.id) {
            return false;
        }
        if (Double.doubleToLongBits(this.longtitude) != Double.doubleToLongBits(other.longtitude)) {
            return false;
        }
        if (Double.doubleToLongBits(this.latitude) != Double.doubleToLongBits(other.latitude)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 17 * hash + (int) (this.id ^ (this.id >>> 32));
        hash = 17 * hash + (int) (Double.doubleToLongBits(this.longtitude) ^ (Double.doubleToLongBits(this.longtitude) >>> 32));
        hash = 17 * hash + (int) (Double.doubleToLongBits(this.latitude) ^ (Double.doubleToLongBits(this.latitude) >>> 32));
        return hash;
    }



}
